//
//  iterator.h
//  pr_fun1
//
//  Created by chenyh on 2021/1/25.
//

#ifndef iterator_h
#define iterator_h

#include <stdio.h>

#pragma once;
///迭代器接口
typedef void * iterator_t;
typedef void (*iterator_next_t)(iterator_t *p_iter);
typedef void (*iterator_prev_t)(iterator_t *p_iter);
//迭代器接口（if表示interface，由具体容器实现,比如，链表。数组等）
typedef struct _iterator_if {
    iterator_next_t pfn_next;   //调用迭代器后移的函数指针，相当于p1++
    iterator_prev_t pfn_prev;   //调用迭代器前移的函数指针，相当于p2--
}iterator_if_t;




void iterator_if_init(iterator_if_t *p_if,iterator_prev_t pfn_next,iterator_prev_t pfn_prev);
void iterator_next(iterator_if_t *p_if,iterator_t *p_iter); //让迭代器指向容器的下一个数据
void iterator_prev(iterator_if_t *p_if,iterator_t *p_iter);


typedef int(*compare_t)(iterator_t it1,iterator_t it2);
typedef void(*swap_t)(iterator_t it1,iterator_t it2);
void iter_sort(iterator_if_t *p_if,iterator_t begin,iterator_t end,compare_t compare,swap_t swap);

typedef int(*visit_t)(void *p_arg,iterator_t it);

void iter_foreach(iterator_if_t *p_if,iterator_t begin,iterator_t end,visit_t visit,void *p_arg);

typedef int element_type_t;
static void __array_iterator_next(iterator_t *p_iter);
static void __array_iterator_prev(iterator_t *p_iter);
void array_iterator_if_get(iterator_if_t *p_if);

#endif /* iterator_h */
